import {createAction, createThunkAction} from "../../lib/redux-utils";
import {get, postForm, postJson} from "../../lib/http";
import {getPrincipal} from "../../lib/identity";

const principal = getPrincipal();
const path = "/containerOrder";
const ACTION_PREFIX = "CONTAINER_ORDER.";
export const query = createThunkAction(ACTION_PREFIX + "QUERY", params =>
    postJson(path + "/query", params)
);
export const showCreate = createAction(ACTION_PREFIX + "SHOW_CREATE");
export const hideCreate = createAction(ACTION_PREFIX + "HIDE_CREATE");
export const showEdit = createAction(ACTION_PREFIX + "SHOW_EDIT");
export const hideEdit = createAction(ACTION_PREFIX + "HIDE_EDIT");
export const updateModel = createAction(ACTION_PREFIX + "UPDATE_MODEL");

export const create = createThunkAction(ACTION_PREFIX + "CREATE", params =>
    postJson(path + "/create", params)
);
export const modify = createThunkAction(ACTION_PREFIX + "MODIFY", params =>
    postJson(path + "/modify", params)
);
export const del = createThunkAction("", params =>
    get(path + "/del/" + params + "/" + principal.id)
);
export const importContainerOrder = createThunkAction(ACTION_PREFIX + "IMPORT", params =>
    postForm(path + "/import/" + params.opId, params)
);